package cn.gjculture.shopping.api.controller;

import cn.gjculture.shopping.api.entity.PageInfo;
import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.entity.Authority;
import cn.gjculture.shopping.api.service.AuthorityService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/authority")
public class AuthorityController {
    @Autowired
    AuthorityService authorityService;
    
    @ApiOperation(value = "新增权限", notes = "新增权限")
    @ApiImplicitParam(name = "Authority", value = "权限对象", required = true, dataType = "Object")
    @PostMapping
    public Return save(Authority authority) {
        Return ret = new Return();
        if(authorityService.insert(authority)>0){
            ret.getCommon().setRet(true);
        }
        return ret;

    }
    @ApiOperation(value = "修改权限", notes = "修改权限")
    @ApiImplicitParam(name = "Authority", value = "权限对象", required = true, dataType = "Object")
    @PutMapping
    public Return<Authority> update(Authority authority){
        Return<Authority> ret=new Return<>();
        if(authorityService.update(authority)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }

    @ApiOperation(value = "获取权限列表", notes = "获取权限列表")
    @GetMapping
    public Return<List<Authority>> query(PageInfo pageInfo) {
        Return<List<Authority>> ret = new Return<>();
        List<Authority> authorities = authorityService.query();
        ret.setData(authorities);
        return ret;
    }

    @ApiOperation(value = "获取权限", notes = "获取权限")
    @ApiImplicitParam(name = "authorityId", value = "权限ID", required = true, dataType = "String",paramType = "path")
    @GetMapping(value = "/{authorityId}")
    public Return<Authority> gitActivity(@PathVariable(value = "authorityId") String authorityId) {
        Return<Authority> ret = new Return<>();
        Authority authority = authorityService.queryById(authorityId);
        ret.setData(authority);
        return ret;
    }

    @ApiOperation(value = "删除权限", notes = "删除权限")
    @ApiImplicitParam(name = "authorityIds", value = "权限ID", required = true, dataType = "String",paramType = "path")
    @DeleteMapping(value = "/{authorityIds}")
    public Return<Authority> delete(@PathVariable(value = "authorityIds") List<String> authorityIds) {
        Return<Authority> ret = new Return<>();
        if(authorityService.delete(authorityIds)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }
}
